/**
 * 看房详情对话框
 */
var HouseLookInfo = {
    id: "houselookinfoTable",//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
HouseLookInfo.initColumn = function () {
    var columns = [
        {field: 'selectItem', radio: true},
        {title: 'id', field: 'id', align: 'center', valign: 'middle'},
        {title: '预约人', field: 'looker_name', align: 'center', valign: 'middle', sortable: true},
        {title: '房源编号', field: 'house_id', align: 'center', valign: 'middle', sortable: true},
        {title: '砍价金额', field: 'cut_money', align: 'center', valign: 'middle', sortable: true},
        {title: '砍服务费', field: 'service_charge', align: 'center', valign: 'middle', sortable: true},
        {title: '完结状态', field: 'end', align: 'center', valign: 'middle', sortable: true},
        {title: '申请日期', field: 'apply_date', align: 'center', valign: 'middle', sortable: true},
        {title: '审核人', field: 'auditor', align: 'center', valign: 'middle', sortable: true}];
    return columns;
};

/**
 * 检查是否选中
 */
HouseLookInfo.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        HouseLookInfo.seItem = selected[0];
        return true;
    }
};

/**
 * 点击详情按钮时
 * @param userId 管理员id
 */
HouseLookInfo.openHouseInfo = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '看房申请详情',
            area: ['900px', '350px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/houselookinfo/view/' + this.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除
 */
HouseLookInfo.delete = function () {
    if (this.check()) {

        var operation = function(){
            var ajax = new $ax(Feng.ctxPath + "/houselookinfo/delete", function () {
                Feng.success("删除成功!");
                HouseLookInfo.table.refresh();
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set("id",HouseLookInfo.seItem.id);
            ajax.start();
        };

        Feng.confirm("是否确定刪除?", operation);
    }
};

HouseLookInfo.resetSearch = function () {
    $("#house_id").val("");
    $("#beginTime").val("");
    $("#endTime").val("");

    HouseLookInfo.search();
}

HouseLookInfo.search = function () {
    var queryData = {};

    queryData['house_id'] = $("#house_id").val();
    queryData['beginTime'] = $("#beginTime").val();
    queryData['endTime'] = $("#endTime").val();

    HouseLookInfo.table.refresh({query: queryData});
}

$(function () {
    var defaultColunms = HouseLookInfo.initColumn();
    var table = new BSTable("houselookinfoTable", "/houselookinfo/list", defaultColunms);
    table.setPaginationType("client");
    HouseLookInfo.table = table.init();


});
